package net.luosheng.contactpatch;

import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceChangeListener;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends PreferenceActivity implements
		OnPreferenceChangeListener {

	private boolean isSpaceWanted;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		PreferenceManager prefMgr = getPreferenceManager();

		addPreferencesFromResource(R.layout.pref);

		StatusPreference mStatusPref = new StatusPreference(this);
		mStatusPref.setSelectable(false);

		getPreferenceScreen().addPreference(mStatusPref);

		prefMgr.findPreference("add_space").setOnPreferenceChangeListener(this);
	}

	@Override
	public void onConfigurationChanged(Configuration newConfiguration) {
		super.onConfigurationChanged(newConfiguration);
	}

	private class StatusPreference extends Preference implements
			OnClickListener {
		private View mView;
		private Button btnUpdate;

		public StatusPreference(Context context) {
			super(context);
		}

		@Override
		public View getView(View convertView, ViewGroup parent) {
			if (mView == null) {
				mView = getLayoutInflater().inflate(R.layout.status, parent,
						false);
				btnUpdate = (Button) findViewById(R.id.ButtonFix);
				btnUpdate.setOnClickListener(this);
			}
			return mView;
		}

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub

		}
	}

	@Override
	public boolean onPreferenceChange(Preference preference, Object newValue) {

		if (preference.getKey() == PrefStore.IS_SPACE_WANTED)
			isSpaceWanted = (Boolean) newValue;

		return true;
	}

}